home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 17.3 KB | 593 lines | [TEXT/MPS ] |
- /*
- File: ShapeCommands.cpp
-
- Contains: Link Commands Implementation
-
- Written by: Mike Halpin
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- DrawEditor Includes --
-
- #ifndef _LINKCOMMANDS_
- #include "LinkCommands.h"
- #endif
-
- #ifndef _SHAPES_
- #include "Shapes.h"
- #endif
-
- #ifndef _SELECTION_
- #include "Selection.h"
- #endif
-
- #ifndef _DRAWEDITORGLOBALS_
- #include "DrawEditorGlobals.h"
- #endif
-
- #ifndef _DRAWEDITOR_
- #include "DrawEditor.h"
- #endif
-
- #ifndef _DRAWEDITORUTILS_
- #include "DrawEditorUtils.h"
- #endif
-
- #ifndef _LINK_
- #include "Link.h"
- #endif
-
- #ifndef _UTILERRS_
- #include "UtilErrs.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODLinkSpec_xh
- #include <LinkSpec.xh>
- #endif
-
- #ifndef SOM_ODLink_xh
- #include <Link.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _ISOSTR_
- #include "ISOStr.h" // ODISOStrFromCStr
- #endif
-
- //=============================================================================
- // class CPasteLinkCommand
- //=============================================================================
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::CPasteLinkCommand
- //---------------------------------------------------------------------------------------
-
- CPasteLinkCommand::CPasteLinkCommand( DrawEditor* theEditor,
- CSelection* selection,
- ODStorageUnit* contentSU,
- ODPasteAsResult& paResult,
- ODBoolean defaultIsMerge) :
- CCommand(theEditor, kODTrue, kODTrue, kUndoPasteLinkIndex, kRedoPasteLinkIndex)
- {
- fSelection = selection;
- fContentSU = contentSU;
- fPaResult = paResult;
-
- // we're going to 'steal' the kind string in the paResult, which would otherwise just get
- // deleted by the caller, and give it to the link. Clear the field so it won't be deleted by the caller.
-
- paResult.selectedKind = kODNULL;
-
- // we're not going to use the translateKind. Clear the field in our copy
- // and allow the caller to delete the string.
-
- fPaResult.translateKind = kODNULL;
-
- fDefaultIsMerge = defaultIsMerge;
-
- fSubscribeLink = kODNULL;
-
- this->SetActionType(kODBeginAction);
-
- }
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::~CPasteLinkCommand
- //---------------------------------------------------------------------------------------
-
- CPasteLinkCommand::~CPasteLinkCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::Commit
- //---------------------------------------------------------------------------------------
-
- void CPasteLinkCommand::Commit(Environment* ev, ODDoneState state)//Override
-
- {
- CCommand::Commit (ev, state);
-
- if (state == kODUndone)
- {
- fSubscribeLink->RemoveShapes(ev, kODTrue);
- delete fSubscribeLink;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::DoCommand
- //---------------------------------------------------------------------------------------
-
- void CPasteLinkCommand::DoCommand(Environment* ev)
- {
- CCommand::DoCommand (ev);
-
- ODLinkSpec* linkSpec = kODNULL;
- ODLink* odLink = kODNULL;
- ODDraft* draft = fDrawEditor->GetDraft(ev);
- ODLinkInfo linkInfo;
-
- // give the selectedKind string to the linkInfo and clear the fPaResult reference.
- // doing before TRY block simplifies CATCH_ALL block
-
- linkInfo.kind = fPaResult.selectedKind;
- fPaResult.selectedKind = kODNULL;
-
- // Empty the selection
- fSelection->CloseSelection(ev);
-
- ODVolatile(linkSpec);
- ODVolatile(odLink);
- ODVolatile(linkInfo);
-
- linkSpec = draft->CreateLinkSpec(ev, kODNULL, kODNULL);
-
- fContentSU->Focus(ev, kODPropLinkSpec, kODPosUndefined, (ODValueType)kODNULL, 0, kODPosUndefined);
- linkSpec->ReadLinkSpec(ev, fContentSU);
-
- TRY
- // ---- Establish the Link ----
- odLink = draft->AcquireLink(ev, (ODStorageUnitID)0, linkSpec); // use linkSpec to retrieve the link
- delete linkSpec;
-
- CATCH_ALL
-
- delete linkSpec;
- delete linkInfo.kind;
- this->AbortLink(ev);
- RERAISE;
-
- ENDTRY
-
- ASSERT_NOT_NULL(odLink);
-
- linkInfo.change = kODUnknownUpdate; // not yet updated
- GetDateTime(&linkInfo.creationTime);
- linkInfo.changeTime = linkInfo.creationTime;
- linkInfo.autoUpdate = fPaResult.autoUpdateSetting;
-
- // In case of a low-mem failure, we'll be proper and release the ODLink. Once
- // we have a CSubscribeLink, it's going to be responsible for that.
- TRY
- // Create the CSubscribeLink
- fSubscribeLink = new CSubscribeLink(odLink, fSelection, linkInfo, fPaResult,
- fDefaultIsMerge);
- CATCH_ALL
- odLink->Release(ev);
- this->AbortLink(ev);
- RERAISE;
- ENDTRY
-
- // set up the CSubscribeLink behavior for first update.
- this->SetUpdateParameters();
-
- fSubscribeLink->Subscribe(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::RedoCommand
- //---------------------------------------------------------------------------------------
-
- void CPasteLinkCommand::RedoCommand(Environment* ev)//Override
-
- {
- CCommand::RedoCommand (ev);
-
- fSubscribeLink->AddToPart(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::UndoCommand
- //---------------------------------------------------------------------------------------
-
- void CPasteLinkCommand::UndoCommand(Environment* ev)//Override
- {
- CCommand::UndoCommand (ev);
-
- fSubscribeLink->RemoveFromPart(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::SetUpdateParameters
- //---------------------------------------------------------------------------------------
-
- void CPasteLinkCommand::SetUpdateParameters()
- {
- // Because a cross document link does not actually complete synchronously, in order that
- // CreateLink at the source document be part of a single undoable transaction, we tag
- // the link so that it will create a CEndPasteLinkCommand to terminate the transaction when
- // it gets it's first real update.
-
- fSubscribeLink->SetCommand(this);
- }
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::CompleteLink
- //---------------------------------------------------------------------------------------
-
- void CPasteLinkCommand::CompleteLink(Environment* ev)
- {
- this->WriteAction(ev, kODEndAction);
- }
-
- //---------------------------------------------------------------------------------------
- // CPasteLinkCommand::AbortLink
- //---------------------------------------------------------------------------------------
-
- void CPasteLinkCommand::AbortLink(Environment* ev)
- {
- this->AbortCommand(ev);
- fSubscribeLink = kODNULL;
- }
-
-
-
-
- //=============================================================================
- // CDropLinkCommand
- //=============================================================================
-
- //---------------------------------------------------------------------------------------
- // CDropLinkCommand::CDropLinkCommand
- //---------------------------------------------------------------------------------------
-
- CDropLinkCommand::CDropLinkCommand( DrawEditor* theEditor,
- CSelection* selection,
- ODStorageUnit* dropSU,
- ODPoint dropPoint,
- ODPasteAsResult& paResult,
- ODBoolean defaultIsMerge) :
- CPasteLinkCommand(theEditor, selection, dropSU, paResult, defaultIsMerge)
- {
- fDropPoint = dropPoint;
-
- // override behavior of CPasteLinkCommand. Drag initiator handles begin and end actions.
- this->SetActionType(kODSingleAction);
- }
-
-
- //---------------------------------------------------------------------------------------
- // CDropLinkCommand::~CDropLinkCommand
- //---------------------------------------------------------------------------------------
-
- CDropLinkCommand::~CDropLinkCommand()
- {
- }
-
-
- //---------------------------------------------------------------------------------------
- // CDropLinkCommand::SetUpdateParameters
- //---------------------------------------------------------------------------------------
-
- void CDropLinkCommand::SetUpdateParameters()
- {
- // As of current recipes, Drag initiator must add begin and end actions. This means that
- // if this creates a cross document link, then the CreateLink at the source will become a
- // separate undoable transaction rather than part of the same transaction as the drag and drop w/link
-
- CPasteLinkCommand::SetUpdateParameters();
-
- // So the first update goes where the user dropped.
- fSubscribeLink->SetOriginPoint(fDropPoint);
- }
-
- //---------------------------------------------------------------------------------------
- // CDropLinkCommand::CompleteLink
- //---------------------------------------------------------------------------------------
-
- void CDropLinkCommand::CompleteLink(Environment* ev)
- {
- // Do nothing. Drag initiator writes kODEndAction.
- }
-
- //---------------------------------------------------------------------------------------
- // CDropLinkCommand::AbortLink
- //---------------------------------------------------------------------------------------
-
- void CDropLinkCommand::AbortLink(Environment* ev)
- {
- fSubscribeLink = kODNULL;
- }
-
-
-
- //=============================================================================
- // class CBreakLinkCommand
- //=============================================================================
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkCommand::CBreakLinkCommand
- //---------------------------------------------------------------------------------------
-
- CBreakLinkCommand::CBreakLinkCommand(DrawEditor* theEditor, CSubscribeLink* link):
- CCommand(theEditor, kODTrue, kODTrue, kUndoBreakLinkIndex, kRedoBreakLinkIndex)
- {
- fSubscribeLink = link;
- }
-
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkCommand::~CBreakLinkCommand
- //---------------------------------------------------------------------------------------
-
- CBreakLinkCommand::~CBreakLinkCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkCommand::Commit
- //---------------------------------------------------------------------------------------
-
- void CBreakLinkCommand::Commit(Environment* ev, ODDoneState state)//Override
- {
- CCommand::Commit (ev, state);
-
- if (state == kODDone || state == kODRedone)
- {
- delete fSubscribeLink;
- }
- }
-
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkCommand::DoCommand
- //---------------------------------------------------------------------------------------
-
- void CBreakLinkCommand::DoCommand(Environment* ev)//Override
-
- {
- CCommand::DoCommand (ev);
- fSubscribeLink->Unsubscribe(ev);
- }
-
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkCommand::RedoCommand
- //---------------------------------------------------------------------------------------
-
- void CBreakLinkCommand::RedoCommand(Environment* ev)//Override
-
- {
- CCommand::RedoCommand (ev);
- fSubscribeLink->Unsubscribe(ev);
- }
-
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkCommand::UndoCommand
- //---------------------------------------------------------------------------------------
-
- void CBreakLinkCommand::UndoCommand(Environment* ev)//Override
-
- {
- CCommand::UndoCommand (ev);
- fSubscribeLink->Subscribe(ev);
- }
-
- //=============================================================================
- // class CBreakLinkSourceCommand
- //=============================================================================
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkSourceCommand::CBreakLinkSourceCommand
- //---------------------------------------------------------------------------------------
-
- CBreakLinkSourceCommand::CBreakLinkSourceCommand(DrawEditor* theEditor, CPublishLink* link):
- CCommand(theEditor, kODTrue, kODTrue, kUndoBreakLinkIndex, kRedoBreakLinkIndex)
- {
- fPublishLink = link;
- fHadCommandOutstanding = kODFalse;
- }
-
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkSourceCommand::~CBreakLinkSourceCommand
- //---------------------------------------------------------------------------------------
-
- CBreakLinkSourceCommand::~CBreakLinkSourceCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkSourceCommand::Commit
- //---------------------------------------------------------------------------------------
-
- void CBreakLinkSourceCommand::Commit(Environment* ev, ODDoneState state)//Override
- {
- CCommand::Commit (ev, state);
-
- fPublishLink->SetHasCommandOutstanding(fHadCommandOutstanding);
-
- if (state == kODDone || state == kODRedone && !fHadCommandOutstanding)
- {
- if (fDrawEditor->GetPendingPublish() != fPublishLink && fDrawEditor->GetPendingDragPublish() != fPublishLink)
- delete fPublishLink;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkSourceCommand::DoCommand
- //---------------------------------------------------------------------------------------
-
- void CBreakLinkSourceCommand::DoCommand(Environment* ev)//Override
-
- {
- CCommand::DoCommand (ev);
-
- fHadCommandOutstanding = fPublishLink->GetHasCommandOutstanding();
- fPublishLink->SetHasCommandOutstanding(kODTrue);
-
-
- // It doesn't make sense to allow the user to create new destinations for this link
- // after it's been broken. We don't worry about a pending drag publisher because that
- // expires when the drag is completed.
-
- if (fDrawEditor->GetPendingPublish() == fPublishLink)
- fDrawEditor->DeletePendingPublish(ev);
-
- fPublishLink->Unpublish(ev);
-
- }
-
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkSourceCommand::RedoCommand
- //---------------------------------------------------------------------------------------
-
- void CBreakLinkSourceCommand::RedoCommand(Environment* ev)//Override
-
- {
- CCommand::RedoCommand (ev);
-
- // A link spec for this link could have been placed on the clipboard while the break was 'undone'
- if (fDrawEditor->GetPendingPublish() == fPublishLink)
- fDrawEditor->DeletePendingPublish(ev);
-
- fPublishLink->Unpublish(ev);
- }
-
-
- //---------------------------------------------------------------------------------------
- // CBreakLinkSourceCommand::UndoCommand
- //---------------------------------------------------------------------------------------
-
- void CBreakLinkSourceCommand::UndoCommand(Environment* ev)//Override
-
- {
- CCommand::UndoCommand (ev);
- fPublishLink->Publish(ev);
- }
-
-
- //=============================================================================
- // class CCreateLinkCommand
- //=============================================================================
-
- //---------------------------------------------------------------------------------------
- // CCreateLinkCommand::CCreateLinkCommand
- //---------------------------------------------------------------------------------------
-
- CCreateLinkCommand::CCreateLinkCommand(DrawEditor* theEditor, CPublishLink* link):
- CCommand(theEditor, kODTrue, kODTrue, kUndoBreakLinkIndex, kRedoBreakLinkIndex)
- {
- fPublishLink = link;
- }
-
-
- //---------------------------------------------------------------------------------------
- // CCreateLinkCommand::~CCreateLinkCommand
- //---------------------------------------------------------------------------------------
-
- CCreateLinkCommand::~CCreateLinkCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CCreateLinkCommand::Commit
- //---------------------------------------------------------------------------------------
-
- void CCreateLinkCommand::Commit(Environment* ev, ODDoneState state)
- {
- CCommand::Commit (ev, state);
-
- if (fPublishLink)
- {
- fPublishLink->SetHasCommandOutstanding(kODFalse);
-
- if (state == kODUndone)
- {
- if (fDrawEditor->GetPendingPublish() != fPublishLink && fDrawEditor->GetPendingDragPublish() != fPublishLink)
- delete fPublishLink;
- }
- }
- }
-
-
- //---------------------------------------------------------------------------------------
- // CCreateLinkCommand::DoCommand
- //---------------------------------------------------------------------------------------
-
- void CCreateLinkCommand::DoCommand(Environment* ev)
-
- {
- CCommand::DoCommand (ev);
-
- TRY
- fPublishLink->Publish(ev);
- fPublishLink->ContentUpdated(ev, fDrawEditor->GetSession(ev)->UniqueUpdateID(ev));
- CATCH_ALL
- this->AbortCommand(ev);
- fPublishLink = kODNULL;
- ENDTRY
-
- fPublishLink->SetHasCommandOutstanding(kODTrue);
- }
-
-
- //---------------------------------------------------------------------------------------
- // CCreateLinkCommand::RedoCommand
- //---------------------------------------------------------------------------------------
-
- void CCreateLinkCommand::RedoCommand(Environment* ev)//Override
-
- {
- CCommand::RedoCommand (ev);
- fPublishLink->Publish(ev);
- }
-
-
- //---------------------------------------------------------------------------------------
- // CCreateLinkCommand::UndoCommand
- //---------------------------------------------------------------------------------------
-
- void CCreateLinkCommand::UndoCommand(Environment* ev)//Override
-
- {
- CCommand::UndoCommand (ev);
- fPublishLink->Unpublish(ev);
- }